using System;
using System.Collections;

namespace Elte.SqlSpIdx.Parser
{
    public class VariableMapper
    {
        private Hashtable mapper;

        public VariableMapper(string columnnames)
        {
            this.mapper = new Hashtable();
            string[] arr = columnnames.Split(',');
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                string s = arr[i];
                s = s.Trim(); // remove whitespace from beginning and end
                this.mapper.Add(s, i);
            }
        }

        public int GetIndex(string s)
        {
            if (this.mapper.ContainsKey(s) == false)
                return -1;
            else
                return (int)this.mapper[s];
        }

        public int GetDimension()
        {
            return this.mapper.Count;
        }
    }
}
